package com.yaojiaxun.logisticsPlatformSystem.controller;

import com.yaojiaxun.logisticsPlatformSystem.entity.News;
import com.yaojiaxun.logisticsPlatformSystem.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @Auther: yjx_j
 * @Date: 2019/2/20 13:03
 * @Description:
 */
@Controller
public class NewsController {
    @Autowired
    private NewsService newsService;

    @RequestMapping("/news_manage")
    public String newsManage(@RequestParam(defaultValue = "1") Integer page, Map<String, Object> map){
        map.put("pageDTO", newsService.findPage(page));
        return "system/news/news_manage";
    }

    @RequestMapping("/newsAddBefore")
    public String newsAddBefore(){
        return "system/news/news_add";
    }

    @RequestMapping("/news_add_after")
    public String newsAddAfter(News news){
        newsService.addNews(news);
        return "redirect:/news_manage";
    }

    @RequestMapping("/news_detail")
    public String newsDetail(@RequestParam("newsId") Long newsId, Map<String, Object> map){
        map.put("newsInfo", newsService.selectNews(newsId));
        return "system/news/news_detail";
    }

    @RequestMapping("/news_update_after")
    public String newsUpdateAfter(News news){
        newsService.updateNews(news);
        return "redirect:/news_manage";
    }

    @RequestMapping("/newsDelete")
    public String deleteNews(@RequestParam("newsId") Long newsId){
        newsService.deleteNews(newsId);
        return "redirect:/news_manage";
    }
}
